<template>
	<view class="page">
		<view class="body" v-if="title_text ==1">
			<view class="body_cont">
				<view>请输入旧登录密码</view>
				<view class="body_cont_">
					<input type="text" placeholder="留空表示不修改" class="input" v-model="password" />
				</view>
			</view>
			<view class="body_cont">
				<view>请确认新登录密码</view>
				<view class="body_cont_">
					<input type="text" placeholder="留空表示不修改" class="input" v-model="old_password" />
				</view>
			</view>
		</view>
		<view class="body" v-if="title_text == 2">
			<view class="body_cont">
				<view>请输入支付密码</view>
				<view class="body_cont_">
					<input type="password" placeholder="请输入支付密码" class="input" maxlength="6" v-model="password" />
				</view>
			</view>
			<view class="body_cont">
				<view>请确认支付密码</view>
				<view class="body_cont_">
					<input type="password" placeholder="请确认支付密码" class="input" maxlength="6" v-model="old_password" />
				</view>
			</view>
		</view>
		<view class="btn btn_css" @click="submit">
			提交
		</view>
	</view>
</template>

<script>
	import {
		getRestPayPwd,
		getResetpwd
	} from '../../api/revise/index.js'
	export default {
		data() {
			return {
				title_text: '',
				password: '', //密码
				old_password: '' //旧密码

			}
		},
		onLoad(e) {
			this.title_text = e.login_password;
			this.title();
		},
		methods: {
			// 修改标签头
			title() {
				if (this.title_text == 1) {
					uni.setNavigationBarTitle({
						title: '修改登录密码'
					})
				} else if (this.title_text == 2) {
					uni.setNavigationBarTitle({
						title: '修改支付密码'
					})
				}
			},
			// 提交数据{
			submit() {
				if (this.title_text == 1) {
					var data = {
						oldpwd: this.password,
						newpwd: this.old_password,
					};
					getResetpwd(data).then(res => {
						uni.showToast({
							icon: 'none',
							title: res.msg,
						})
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					})
				} else if (this.title_text == 2) {
					var data = {
						oldpwd: this.password,
						password: this.old_password,
					};
					getRestPayPwd(data).then(res => {
						uni.showToast({
							icon: 'none',
							title: res.msg,
						})
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100%;

		.body {
			.body_cont {
				padding: 20rpx 0;

				.body_cont_ {

					.input {
						margin-top: 20rpx;
						background-color: #f5f5f5;
						font-size: 20px;
						padding: 20rpx;
						border-radius: 15rpx;
					}
				}
			}
		}

		.btn_css {
			margin-top: 50px;
		}
	}
</style>